package com.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import com.sun.istack.internal.NotNull;

@Entity
@NamedQueries({
		@NamedQuery(name = "User.findUserByUsernamePassword", query = "select u from User u where u.username = :username and u.password = :password"),
		@NamedQuery(name = "User.findUserByUsername", query = "select u from User u where u.username = :username and u.active = true")
})

public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String FIND_BY_USERNAME_PASSWORD = "User.findUserByUsernamePassword";
	public static final String FIND_BY_USERNAME = "User.findUserByUsername";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@NotNull
	@Column(unique = true)
	private String username;
	
	@NotNull
	private String password;
	private String name;
	private boolean active;
	
	@ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER)
	@Enumerated(EnumType.STRING)
	private List<Role> roles;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
	
	
}